package com.soupinabox;

import javax.imageio.ImageIO;
import java.awt.image.BufferedImage;
import java.io.IOException;

/**
 * Item.java
 *
 * Author:  Taw
 * Date:    4/11/14
 */
public class Item {
    BufferedImage img;
    String[] names;
    String ocrname;
    public int index = 0;

    private Item(String ocrname, String... names){
        this.ocrname=ocrname;
        this.names = names;
        //System.out.println(formatToFile(names[0])+".png");
        try{
            img = ImageIO.read(ItemTracker.class.getResource("/items/"+formatToFile(names[0])+".png"));
            //img = ImageIO.read(new File("ITEMS"+File.separator+formatToFile(names[0])+".png"));
        }catch(IOException e){
            //couldn't load image
        }
        if(names[0].equals("heart")){
            this.names=new String[]{"<3"};
        }
    }

    public String toString(){
        return names[0];
    }

    public boolean equals(Object o){
        if(o instanceof Item){
            return ((Item)o).index == index;
        }
        return false;
    }

    public static String formatToFile(String s){
        return s.replace(".","").replace("'","").replace("!","").replace("-"," ");
    }

    public static int[] searchFor(String str){
        str=str.toLowerCase();
        int[] ids=new int[ITEMS.length];
        float[] match=new float[ITEMS.length];
        int count=0;
        for(int i=0;i< ITEMS.length;i++){
            float bestmatch=0;
            for(String name: ITEMS[i].names){
                for(int j=str.length();j>0;j--){
                    if(name.contains(str.substring(0,j)) || formatToFile(name).contains(str.substring(0,j))){
                        double m=Math.pow(j / (float) str.length(), 2)*(Math.log(j)+1)/(Math.log(name.length())+1)*100*(name.indexOf(str.substring(0,j))==0?1.1:1);
                        //System.out.println(str+" => " + name + " : "+str.substring(0,j)+"    "+m);
                        if(m > bestmatch) bestmatch = (float)m;
                        break;
                    }
                }
            }
            if(bestmatch > 0){
                ids[count]=i;
                match[count++]=bestmatch;
            }
        }

        if(count==0){
            for(int i = 0;i< ITEMS.length;i++){
                ids[i]=i;
            }
            return ids;
        }

        for(int i=0;i<count;i++){
            int id=ids[i];
            float m=match[i];
            int j=i;
            while(j > 0 && match[j-1] < m){
                match[j]=match[j-1];
                ids[j]=ids[j-1];
                j--;
            }
            match[j]=m;
            ids[j]=id;
        }
        for(int i=0;i<count;i++){
            if(match[i]<match[0]*.16){
                count=i;
                break;
            }
        }
        //for(int i=0;i<count;i++){
        //System.out.println("   "+i+": "+ITEMS[ids[i]].names[0]);
        //}
        return java.util.Arrays.copyOf(ids,count);
    }

    public static Item[] ITEMS =
            {
                    new Item("THESADONION","sad onion"),
                    new Item("THEINNEREYE","the inner eye"," triple shot"),
                    new Item("SPOONBENDER","spoon bender"," homing tears"),
                    new Item("MAX'SHEAD","max's head"),
                    new Item("MYREFLECTION","my reflection"),
                    new Item("NUMBERONE","number one"),
                    new Item("BLOODOFTHEMARTYR","blood of the martyr"),
                    new Item("BROTHERBOBBY","brother bobby"),
                    new Item("SKATOLE","skatole"),
                    new Item("HALOOFFLIES","halo of flies"),
                    new Item("1UP!","1up"),
                    new Item("MAGICMUSHROOM","magic mushroom"),
                    new Item("THEVIRUS","the virus"),
                    new Item("ROIDRAGE","roid rage"),
                    new Item("<3","heart","<3"),
                    new Item("RAWLIVER","raw liver"),
                    new Item("SKELETONKEY","skeleton key"),
                    new Item("ADOLLAR","a dollar"),
                    new Item("BOOM!","boom!"),
                    new Item("TRANSCENDENCE","transcendence"),
                    new Item("THECOMPASS", "the compass"),
                    new Item("LUNCH","lunch"),
                    new Item("DINNER","dinner"),
                    new Item("DESSERT","dessert"),
                    new Item("BREAKFAST","breakfast"),
                    new Item("ROTTENMEAT","rotten meat"),
                    new Item("WOODENSPOON","wooden spoon"),
                    new Item("THEBELT","the belt"),
                    new Item("MOMSUNDERWEAR","mom's underwear"),
                    new Item("MOMSHEELS","mom's heels"),
                    new Item("MOMSLIPSTICK","mom's lipstick"),
                    new Item("WIRECOATHANGER","wire coat hanger"),
                    new Item("*THEBIBLE","the bible"),
                    new Item("*THEBOOKOFBELIAL","the book of belial"),
                    new Item("*THENECRONOMICON","the necronomicon"),
                    new Item("*THEPOOP!","the poop"),
                    new Item("*MR.BOOM!","mr. boom"),
                    new Item("*TAMMYSHEAD","tammy's head"),
                    new Item("*MOMSBRA","mom's bra"),
                    new Item("*KAMIKAZE!","kamikaze"),
                    new Item("*MOMSPAD","mom's pad"),
                    new Item("BOBSCURSE","bob's curse"," poison bombs"),
                    new Item("*TELEPORT!","teleport!"),
                    new Item("*YUMHEART","yum heart"),
                    new Item("LUCKYFOOT","lucky foot"),
                    new Item("*DOCTORSREMOTE","doctor's remote"),
                    new Item("CUPIDSARROW","cupid's arrow"," piercing shot"),
                    new Item("*SHOOPDAWHOOP!","shoop da whoop"),
                    new Item("STEVEN","steven"),
                    new Item("PENTAGRAM","pentagram"),
                    new Item("DRFETUS","dr. fetus"),
                    new Item("MAGNETO","magneto"),
                    new Item("TREASUREMAP","treasure map"),
                    new Item("MOMSEYE","mom's eye"),
                    new Item("*LEMONMISHAP","lemon mishap"),
                    new Item("DISTANTADMIRATION","distant admiration"),
                    new Item("*BOOKOFSHADOWS","book of shadows"),
                    new Item("WIGGLEWORM","wiggle worm"),
                    new Item("THELADDER","the ladder"),
                    new Item("CHARMOFTHEVAMPIRE","charm of the vampire"),
                    new Item("LITTLESTEVE","little steve"),
                    new Item("THEHALO","the halo"),
                    new Item("*MOMSBOTTLEOFPILLS","mom's bottle of pills"),
                    new Item("THECOMMONCOLD","the common cold"," poison tears  "),
                    new Item("THEPARASITE","the parasite"),
                    new Item("*THEDICE","the dice","d6"),
                    new Item("MR.MEGA","mr. mega"),
                    new Item("*THEPINKINGSHEARS","the pinking shears"),
                    new Item("THEWAFER","the wafer"),
                    new Item("MONEY=POWER","money equals power","money = power"),
                    new Item("MOMSCONTACTS","mom's contacts"),
                    new Item("*THEBEAN","the bean"),
                    new Item("GUARDIANANGEL","guardian angel"),
                    new Item("DEMONBABY","demon baby"),
                    new Item("MOMSKNIFE","mom's knife"),
                    new Item("OUIJABOARD","ouija board"),
                    new Item("9VOLT","9 volt"),
                    new Item("DEADBIRD","dead bird"),
                    new Item("BRIMSTONE","brimstone"),
                    new Item("BLOODBAG","blood bag"),
                    new Item("ODDMUSHROOMTHIN","odd mushroom thin"),
                    new Item("ODDMUSHROOM","odd mushroom thick"),
                    new Item("WHOREOFBABYLON","whore of babylon"),
                    new Item("*MONSTERMANUEL","monster manuel"),
                    new Item("*DEADSEASCROLLS","dead sea scrolls"),
                    new Item("BOBBY-BOMB","bobby-bomb"," homing bombs   "),
                    new Item("*RAZORBLADE","razor blade"),
                    new Item("*FORGETMENOW","forget me now"),
                    new Item("FOREVERALONE","forever alone"),
                    new Item("BUCKETOFLARD","bucket of lard"),
                    new Item("*APONY","a pony"),
                    new Item("BOMBBAG","bomb bag"),
                    new Item("ALUMPOFCOAL","a lump of coal"),
                    new Item("*GUPPYSPAW","guppy's paw"),
                    new Item("GUPPYSTAIL","guppy's tail"),
                    new Item("*IVBAG","iv bag"),
                    new Item("*BESTFRIEND","best friend"),
                    new Item("*REMOTEDETONATOR","remote detonator"),
                    new Item("STIGMATA","stigmata"),
                    new Item("MOMSPURSE","mom's purse"),
                    new Item("PAGEANTBOY","pageant boy"),
                    new Item("SCAPULAR","scapular"),
                    new Item("SPEEDBALL","speed ball"),
                    new Item("BUMFRIEND","bum friend"),
                    new Item("*GUPPYSHEAD","guppy's head"),
                    new Item("*PRAYERCARD","prayer card"),
                    new Item("*NOTCHEDAXE","notched axe"),
                    new Item("INFESTATION","infestation"),
                    new Item("IPECAC","ipecac"),
                    new Item("TOUGHLOVE","tough love"," tooth shot"),
                    new Item("THEMULLIGAN","the mulligan"),
                    new Item("TECHNOLOGY","technology","tech","tech 1"),
                    new Item("TECHNOLOGY2","technology 2","tech 2","tech2"),
                    new Item("MUTANTSPIDER","mutant spider"," quad shot"),
                    new Item("CHEMICALPEEL","chemical peel"),
                    new Item("THEPEEPER!","the peeper"),
                    new Item("HABIT","the habit"),
                    new Item("BLOODYLUST","bloody lust"),
                    new Item("*CRYSTALBALL","crystal ball"),
                    new Item("SPIRITOFTHENIGHT","spirit of the night"),
                    new Item("*CRACKTHESKY","crack the sky"),
                    new Item("ANKH","ankh"),
                    new Item("CELTICCROSS","celtic cross"),
                    new Item("GHOSTBABY","ghost baby"),
                    new Item("*THECANDLE","the candle"),
                    new Item("CAT-O-NINE-TAILS","cat-o-nine-tails"),
                    new Item("*D2O","d20"),
                    new Item("HARLEOUINBABY","harlequin baby"),
                    new Item("EPICFETUS","epic fetus"),
                    new Item("POLYPHEMUS","polyphemus"),
                    new Item("DADDYLONGLEGS","daddy longlegs"),
                    new Item("*SPIDERBUTT","spider butt"),
                    new Item("SACRIFICIALDAGGER","sacraficial dagger","sacrificial dagger","sac dagger"),
                    new Item("MITRE","mitre"),
                    new Item("RAINBOWBABY","rainbow baby"),
                    new Item("*DADSKEY","dads key"),
                    new Item("STEMCELLS","stem cells"),
                    new Item("*PORTABLESLOT!","portable slot"),
                    new Item("HOLYWATER","holy water"),
                    new Item("FATE","fate"),
                    new Item("THEBLACKBEAN","the black bean"),
                    new Item("*WHITEPONY","white pony"),
                    new Item("SACREDHEART","sacred heart"),
                    new Item("TOOTHPICKS","tooth picks","toothpicks"),
                    new Item("HOLYGRAIL","holy grail"),
                    new Item("DEADDOVE","dead dove"),
                    new Item("*BLOODRIGHTS","blood rights"),
                    new Item("GUPPYSHAIRBALL","guppy's hairball"),
                    new Item("ABEL","abel"),
                    new Item("SMBSUPERFAN!","smb super fan"),
                    new Item("PYRO","pyro"),
                    new Item("3DOLLARBILL","3 dollar bill","three dollar bill"),
                    new Item("*TELEPATHYFORDUMMIES","telepathy for dummies"),
                    new Item("MEAT!","meat!"),
                    new Item("MAGIC8BALL","magic 8 ball"),
                    new Item("MOMSCOINPURSE","mom's coin purse"),
                    new Item("SOUEEZY","squeezy"),
                    new Item("JESUSJUICE","jesus juice"),
                    new Item("BOX","box"),
                    new Item("*BOBSROTTENHEAD","bob's rotten head"),
                    new Item("THEBATTERY","the battery"),
                    new Item("STEAMSALE","steam sale"),
                    new Item("*ANARCHISTCOOKBOOK","anarchist cookbook","anarchist's cookbook"),
                    new Item("*THEHOURGLASS","the hourglass"),
                    new Item("SISTERMAGGY","sister maggy"),
                    new Item("CHOCOLATEMILK","chocolate milk"),
                    new Item("GROWTHHORMONES","growth hormones"),
                    new Item("MINIMUSH","mini mush"),
                    new Item("ROSARY","rosary"),
                    new Item("CUBEOFMEAT","cube of meat"),
                    new Item("AOUARTER","a quarter"),
                    new Item("PHD","phd"),
                    new Item("XRAY-VISION","x-ray vision","xray vision","xray glasses"),
                    new Item("*MYLITTLEUNICORN","my little unicorn"),
                    new Item("*BOOKOFREVELATIONS","book of revelations"),
                    new Item("THEMARK","the mark"),
                    new Item("THEPACT","the pact"),
                    new Item("DEADCAT","dead cat"),
                    new Item("LORDOFTHEPIT","lord of the pit"),
                    new Item("*THENAIL","the nail"),
                    new Item("*WENEEDTOGODEEPER","we need to go deeper"),
                    new Item("*DECKOFCARDS","deck of cards"),
                    new Item("*MONSTROSTOOTH","monstro's tooth"),
                    new Item("LOKISHORNS","loki's horns"),
                    new Item("LILCHUBBY","lil' chubby"),
                    new Item("SPIDERBITE","spider bite","spider's bite"),
                    new Item("THESMALLROCK","the small rock"),
                    new Item("SPELUNKERHAT","spelunker hat"),
                    new Item("SUPERBANDAGE","super bandage"),
                    new Item("*THEGAMEKID","the gamekid"),
                    new Item("SACKOFPENNIES","sack of pennies"),
                    new Item("ROBO-BABY","robo-baby"),
                    new Item("LITTLECHAD","little c.h.a.d."),
                    new Item("*THEBOOKOFSIN","the book of sin"),
                    new Item("THERELIC","the relic"),
                    new Item("LITTLEGISH","little gish"),
                    new Item("","guppy"),
                    new Item("","cube of meat x2"),
                    new Item("","cube of meat x3"),
                    new Item("","cube of meat x4"),
                    new Item("","pretty fly"),
                    new Item("","pretty fly x2"),
                    new Item("","pretty fly x3")
            };
}
